use super::Object;
use crate::consts::*;

use std::collections::HashMap;
use std::rc::Rc;

pub struct ObjectSet(HashMap<&'static str, Rc<Object>>);

impl ObjectSet {
    pub fn keyword_set() -> Self {
        Self(
            KEYWORD_SET
                .iter()
                .map(|keyword| (*keyword, Rc::new(Object::Keyword(*keyword))))
                .collect(),
        )
    }

    pub fn operator_set() -> Self {
        Self(
            OPERATOR_SET
                .iter()
                .map(|operator| (*operator, Rc::new(Object::Operator(*operator))))
                .collect(),
        )
    }
}

impl ObjectSet {
    pub fn get(&self, s: &str) -> Option<&Rc<Object>> {
        self.0.get(s)
    }
}

unsafe impl Sync for ObjectSet {}

pub struct RcObject(Rc<Object>);

impl RcObject {
    pub fn new(object: Object) -> Self {
        Self(Rc::new(object))
    }

    pub fn clone(&self) -> Rc<Object> {
        self.0.clone()
    }
}

unsafe impl Sync for RcObject {}